***************** Replication of Franchino, Fabio, and Camilla Mariotto. “Bargaining Outcomes and Success in EU Economic Governance Reforms”. Political Science Research and Methods.

* Step 1 to reproduce Figure A4

version 16

******************************* SENSITIVITY ANALYSIS
*************   COMPUTING POINT PREDICTIONS: Compromise Model (10% selected)
clear all
gen mad=.
save mad_comp.dta, replace

set seed 1234

local v = 0
while `v' <= 1000 {
* Upload original dataset
use NBSmodel_data.dta, clear
gen comp = 0
gen utility_star = .
gen utility = .
order utility utility_star comp

* Modify 20% of actors's positions
/* We test for unsystematic mis-categorization following the re-categorization test proposed by Eric Neumayer and Thomas Plümper.
We have drawn a random sample of twenty percent of the positions. We have then increased by 25 points the position for half of these cases (if it is not located on upper bound) and decreased by 25 points the other half (if it is not located on the lower bound).
We have then estimated the model outcomes. The procedure is repeated for 1,000 samples
*/
***** Select a random sample without replacement of observations
***** change 4 out of 35 obs
generate random = runiform()
sort random
do meaningful_shift_comm.do
drop random

generate random = runiform()
sort random
do meaningful_shift_ep_1.do
drop random

do meaningful_shift_country.do

* Gradient ascent procedure
local i = 0
while `i' <= 100 {
replace utility =	-	v_power1*salience1	*(`i'-	country1	)^2 if	salience1	> 0 &	salience1	!= .
replace utility = utility + (	-	v_power2*salience2	*(`i'-	country2	)^2) if	salience2	> 0 &	salience2	!= .
replace utility = utility + (	-	v_power3*salience3	*(`i'-	country3	)^2) if	salience3	> 0 &	salience3	!= .
replace utility = utility + (	-	v_power4*salience4	*(`i'-	country4	)^2) if	salience4	> 0 &	salience4	!= .
replace utility = utility + (	-	v_power5*salience5	*(`i'-	country5	)^2) if	salience5	> 0 &	salience5	!= .
replace utility = utility + (	-	v_power6*salience6	*(`i'-	country6	)^2) if	salience6	> 0 &	salience6	!= .
replace utility = utility + (	-	v_power7*salience7	*(`i'-	country7	)^2) if	salience7	> 0 &	salience7	!= .
replace utility = utility + (	-	v_power8*salience8	*(`i'-	country8	)^2) if	salience8	> 0 &	salience8	!= .
replace utility = utility + (	-	v_power9*salience9	*(`i'-	country9	)^2) if	salience9	> 0 &	salience9	!= .
replace utility = utility + (	-	v_power10*salience10	*(`i'-	country10	)^2) if	salience10	> 0 &	salience10	!= .
replace utility = utility + (	-	v_power11*salience11	*(`i'-	country11	)^2) if	salience11	> 0 &	salience11	!= .
replace utility = utility + (	-	v_power12*salience12	*(`i'-	country12	)^2) if	salience12	> 0 &	salience12	!= .
replace utility = utility + (	-	v_power13*salience13	*(`i'-	country13	)^2) if	salience13	> 0 &	salience13	!= .
replace utility = utility + (	-	v_power14*salience14	*(`i'-	country14	)^2) if	salience14	> 0 &	salience14	!= .
replace utility = utility + (	-	v_power15*salience15	*(`i'-	country15	)^2) if	salience15	> 0 &	salience15	!= .
replace utility = utility + (	-	v_power16*salience16	*(`i'-	country16	)^2) if	salience16	> 0 &	salience16	!= .
replace utility = utility + (	-	v_power17*salience17	*(`i'-	country17	)^2) if	salience17	> 0 &	salience17	!= .
replace utility = utility + (	-	v_power18*salience18	*(`i'-	country18	)^2) if	salience18	> 0 &	salience18	!= .
replace utility = utility + (	-	v_power19*salience19	*(`i'-	country19	)^2) if	salience19	> 0 &	salience19	!= .
replace utility = utility + (	-	v_power20*salience20	*(`i'-	country20	)^2) if	salience20	> 0 &	salience20	!= .
replace utility = utility + (	-	v_power21*salience21	*(`i'-	country21	)^2) if	salience21	> 0 &	salience21	!= .
replace utility = utility + (	-	v_power22*salience22	*(`i'-	country22	)^2) if	salience22	> 0 &	salience22	!= .
replace utility = utility + (	-	v_power23*salience23	*(`i'-	country23	)^2) if	salience23	> 0 &	salience23	!= .
replace utility = utility + (	-	v_power24*salience24	*(`i'-	country24	)^2) if	salience24	> 0 &	salience24	!= .
replace utility = utility + (	-	v_power25*salience25	*(`i'-	country25	)^2) if	salience25	> 0 &	salience25	!= .
replace utility = utility + (	-	v_power26*salience26	*(`i'-	country26	)^2) if	salience26	> 0 &	salience26	!= .
replace utility = utility + (	-	v_power27*salience27	*(`i'-	country27	)^2) if	salience27	> 0 &	salience27	!= .

* comm and ep positions (exclude if we want only country positions) - commission excluded as it has no voting power
* replace utility = utility + (	-	v_power_com*salience_comm	*(`i'-	comm	)^2)
replace utility = utility + (	-	v_power_ep*salience_ep	*(`i'-	ep_1	)^2) if	ep_rule==2

replace utility_star = utility if `i'==0
replace comp = `i' if utility > utility_star
replace utility_star = utility if utility > utility_star

local i = `i' + 1
}

order utility utility_star comp sq outcome
sort act issue_id
label variable comp "compromise model solution"
label variable utility_star "maximized product of actors' utilities" 

* Compute means of absolute differences between outcomes and model predictions
gen mad=abs(comp-outcome)
collapse mad
label variable mad "mean of absolute differences" 
append using mad_comp.dta
save mad_comp.dta, replace
sleep 100
local v = `v' + 1
}

use mad_comp.dta, clear
mean mad
kdensity mad, nor normopts(lwidth(vvthin)) graphregion(fcolor(white)) legend(off) graphregion(fcolor(white)) ytitle("") xtitle("") text(0.25 17 "mean 19.7" "s.e. 0.03", si(small) place(e)) title("Compromise", si(small)) note("") ylabel(,labsize(small)) xlabel(,labsize(small)) saving(comp, replace)


